import unittest
from common.functions import browser_operation
from page.backstage.backstage_login_page import Backstage
from page.backstage.backstage_index_page import BackStageIndex


# 创建订单类
class OrderCase(unittest.TestCase):
    """订单相关测试"""

    @classmethod
    def setUpClass(cls) -> None:
        # 调用functions打开浏览器
        driver = browser_operation()
        cls.backstage = Backstage(driver)
        cls.backstage.get_website(cls.backstage.backstage_url)
        cls.index = BackStageIndex(driver)

    def test_order_01(self):
        """测试后台订单管理中的订单号可以点击进入订单详情"""
        # 调用后台登录模块方法,进行登录
        self.backstage.implicitly_wait()
        self.backstage.click_X()
        self.backstage.backstage_login()
        self.backstage.input_username('admin')
        self.backstage.input_password('admin123')
        self.backstage.btn_login()
        # 切换到菜单栏frame,点击订单管理
        self.index.change_menu_frame()
        self.index.order_manage()
        # 切换回上一级frame
        self.index.change_parent_frame()
        # 切换到主框架frame
        self.index.change_main_frame()
        # 获取最新一条订单号
        number1 = self.index.order_no1()
        # 点击第一个订单的编号
        self.index.click_order_no1()
        # 进入订单详情获取到对应的订单号
        number2 = self.index.order_number()
        # 断言可以点击成功并显示出对应的订单
        self.assertEqual(number1, number2)

    @classmethod
    def tearDownClass(cls) -> None:
        cls.backstage.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
